<template>
  <div id="register">
    <el-dialog title="注册" width="300px" center :visible.sync="isRegister">
      <el-form
        :model="RegisterUser"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <el-form-item>
          <el-input
            prefix-icon="el-icon-user-solid"
            placeholder="请输入账号"
            v-model="RegisterUser.name"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            prefix-icon="el-icon-view"
            type="password"
            placeholder="请输入密码"
            v-model="RegisterUser.pass"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            prefix-icon="el-icon-view"
            type="password"
            placeholder="请再次输入密码"
            v-model="RegisterUser.confirmPass"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="medium" type="primary" @click="Register" style="width:100%;">注册</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "MyRegister",
	
  props: ["register"],
	
  data() {
    return {
      isRegister: false, // 控制注册组件是否显示
      RegisterUser: {
        name: "",
        pass: "",
        confirmPass: ""
      }
    };
  },
  watch: {
    // 监听父组件传过来的register变量，设置this.isRegister的值
    register: function(val) {
      if (val) {
        this.isRegister = val;
      }
    },
    // 监听this.isRegister变量的值，更新父组件register变量的值
    isRegister: function(val) {
      if (!val) {
        this.$refs["ruleForm"].resetFields();
        this.$emit("fromChild", val);
      }
    }
  },
  methods: {
    Register() {
			// TODO element 自定义表单校验规则
			// TODO 注册API
			var res = {
				data:{
					code: "001",
					msg: "登陆成功！",
					user:{
						userName:'zzl',
						userId:'123'
					}
				}
			}
			if (res.data.code === "001") {
			  // 隐藏注册组件
			  this.isRegister = false;
			  // 弹出通知框提示注册成功信息
			  this.notifySucceed(res.data.msg);
			} else {
			  // 弹出通知框提示注册失败信息
			  this.notifyError(res.data.msg);
			}
    }
  }
};
</script>
<style>
</style>